class Solution {
public:
    vector<vector<int>> threeSum(vector<int>& nums) {
        int left=0;
        int right=0;
        vector<vector<int>> ret;
        sort(nums.begin(),nums.end());
        for(int  i=0;i<nums.size();)
        {
            int tar = nums[i];
            if(tar>0)
            {
                break;
            }
           int left = i+1;
           int right = nums.size()-1;
           tar = -tar;
           while(left<right)
           {
               int n = nums[left]+nums[right];
               if(n>tar)
               {
                   right--;
               }
               else if(n<tar)
               {
                   left++;
               }
                else{
                    ret.push_back({nums[left],nums[right],nums[i]});
                    left++;
                    right--;
                    while(left<right && nums[left]==nums[left-1]) left++;
                    while(left<right && nums[right]==nums[right+1]) right--;
                }
           }
            i++;
            while(i<nums.size() && nums[i]==nums[i-1]) i++;
        }
        return ret;
    }
};